#pragma once

#include"HashTable.h"


namespace MyHash
{
	//template<class K, class Hash = HashFunc<K>>
	template<class K, class Hash = HashFunc<K>>
	class Unordered_set
	{
		struct SetKeyOfT
		{
			const K& operator()(const K& key)
			{
				return key;
			}
		};
	public:
		typedef typename Hash_bucket::HashTable<K, K, SetKeyOfT,Hash>::const_iterator iterator;
		typedef typename Hash_bucket::HashTable<K, K, SetKeyOfT,Hash>::const_iterator const_iterator;

		/*iterator begin()
		{
			return  _ht.begin();
		}

		iterator end()
		{
			return _ht.end();
		}*/

		const_iterator begin()const
		{
			return  _ht.begin();
		}

		const_iterator end()const
		{
			return _ht.end();
		}

		pair<iterator, bool> insert(const K& key)
		{
			//return _ht.Insert(key);
			auto ret = _ht.Insert(key);
			return pair<iterator,bool>(iterator(ret.first._node, ret.first._pht, ret.first._Hashi), ret.second);
		}

		iterator find(const K& key)
		{
			return _ht.Find(key);
		}

		bool erase(const K& key)
		{
			return _ht.Erase(key);
		}
		 
	private:
		Hash_bucket::HashTable<K, K, SetKeyOfT, Hash> _ht;
	};

	void Test_UnorderedSet()
	{
		Unordered_set<int> ht;
		ht.insert(5);
		ht.insert(15);
		ht.insert(52);
		ht.insert(3);

		//auto it = ht.begin();
		Unordered_set<int>::iterator it = ht.begin();
		while (it != ht.end())
		{
			//*it += 2;
			cout << *it << " ";
			++it;
		}
		cout << endl;
	}
}